function stdSpectrum = GET_StdCalibrationSpectrum(obj, varargin)
%GET_STDCALIBRATIONSPECTRUM Summary of this function goes here
%   Detailed explanation goes here
    p=inputParser;
    p.addParameter('isPlot', true, @islogical);
    p.addParameter('average', 100, @(x) isscalar(x) && x > 0);
    p.addParameter('bandwidth', 1e3, @(x) isscalar(x) && x > 0);
    p.addParameter('nPoint', 8192, @(x) isscalar(x) && x > 0);
    p.addParameter('fSpan', 1e3, @(x) isscalar(x) && x > 0);
    p.addParameter('uBound', 20e-6, @(x)  isscalar(x) && x > 0); % noise floor upper bound
    p.addParameter('low_freq_cut', 5, @(x)  isscalar(x) && x > 0); % low frequency cut
    p.parse(varargin{:});
    
    chX = obj.controller.DemodSettings.BXDemodSlow.index; 
    chY = obj.controller.DemodSettings.BYDemodSlow.index; 
    averageNo = p.Results.average;
    
    obj.controller.unLockMagnetometerTransverseFieldX();
    obj.controller.unLockMagnetometerTransverseFieldY(); pause(1);
    obj.recoverWorkingPoint;

    obj.controller.enableMagnetometerCalibrationSignal();
    obj.controller.setMagnetometer_BXDemodSlowChannel('bandwidth', p.Results.bandwidth);
    obj.controller.setMagnetometer_BYDemodSlowChannel('bandwidth', p.Results.bandwidth);

    obj.controller.ziMaster.autoRange();
    obj.controller.ziMaster.sync();
    %%    
    spect = obj.controller.ziMaster.spectrumModule;

    spect.setControl('grid_repetitions', averageNo);
    spect.setParam('spectrum/frequencyspan', p.Results.fSpan);
    spect.setParam('grid/cols', p.Results.nPoint);
    
    spect.reset();
    spect.subscribeChannel(chX, 'sample.X.fft.abs.avg');
    spect.subscribeChannel(chY, 'sample.X.fft.abs.avg');
    stdSpectrum= spect.run();
    spect.unsubscribeChannel();
    
    obj.controller.disableMagnetometerCalibrationSignal();
    obj.controller.setMagnetometer_BXDemodSlowChannel();
    obj.controller.setMagnetometer_BYDemodSlowChannel();
    obj.controller.setCalibrationDemodulationRate();
    %%
    L = log4m.getLogger;
    stdSpectX = stdSpectrum.analyze(chX, 'sample.X.fft.abs.avg', 'uBound', p.Results.uBound, 'range', [p.Results.low_freq_cut inf], ...
        'figHdl', figure('Name', 'Spectrum X'), 'factor', abs(obj.workingPoint.coeffX), 'unit', 'nT', 'isPlot', p.Results.isPlot);
    L.info('GET_StdCalibrationSpectrum', sprintf('f=%3.2e Hz, peak=%3.2e V, nosie = (%3.2e +- %3.2e) V/sqrt(Hz)', stdSpectX.locs, stdSpectX.peaks, stdSpectX.background, stdSpectX.stdBg));
    
    
    stdSpectY = stdSpectrum.analyze(chY, 'sample.X.fft.abs.avg', 'uBound', p.Results.uBound, 'range', [p.Results.low_freq_cut inf], ...
        'figHdl', figure('Name', 'Spectrum Y'), 'factor', abs(obj.workingPoint.coeffY), 'unit', 'nT', 'isPlot', p.Results.isPlot);
    L.info('GET_StdCalibrationSpectrum', sprintf('f=%3.2e Hz, peak=%3.2e V, nosie = (%3.2e +- %3.2e) V/sqrt(Hz)', stdSpectY.locs, stdSpectY.peaks, stdSpectY.background, stdSpectY.stdBg));
end